// pages/lb/lb.js
import {request} from '../../request/index'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tabs:[
            {
                id:0,
                value:"综合",
                isActive:true,
            },
            {
                id:1,
                value:"销量",
                isActive:false,
            },
            {
                id:2,
                value:"价格",
                isActive:false,
            },
        ],
      goodsList:[],
    },      

        QueryParams:{
            query:"",
            cid:"",
            pagenum:1,
            pagesize:10
        },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
       this.QueryParams.cid=options.cid;
       this.getGoodsList();
        wx.showLoading({
            title:"加载中"
        })
        setTimeout(function(){
            wx.hideLoading()
        },5000)
    },
    // 获取商品列表的数据
getGoodsList(){
     request({url:"https://api-hmugo-web.itheima.net/api/public/v1/goods/search",data:this.QueryParams}).then((res)=>{
          this.setData({
            goodsList:res.data.message.goods
        }) 
       console.log(this.data.goodsList);

     })

    //  关闭下拉刷新
    wx.stopPullDownRefresh();
    }, 
    
    // 标题的点击事件
    handelTabsItemChange(e){
        console.log(e);
        const {index}=e.detail;
        let {tabs}=this.data;
        tabs.forEach((v,i)=>i===index?v.isActive=true:v.isActive=false);
        this.setData({
            tabs
        })
    },
    // 页面上滑，滚动条触发事件
    onReachBottom(){
        console.log("页面触底");

    },
    // 下拉刷新事件
    onPullDownRefresh(){
    }
})

